package com.loopy.statement;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Date;
import java.util.Properties;
import java.util.Scanner;

public class PreparedStatement_ {
    public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入管理员名字");
        String admin_name = scanner.next();
        System.out.println("请输入密码");
        String admin_pwd = scanner.next();
        Properties properties = new Properties();
        properties.load(new FileInputStream("src\\mysql.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driver = properties.getProperty("driver");
        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
//        System.out.println("connection="+connection);
//        String sql="SELECT name,pwd from admin WHERE name=? and pwd=?";
        //对象是实现了PreparedStatement接口的实现类的对象
//        String sql="insert into admin values(?,?)";
//        String sql="update admin set name='king' where name='tom'";
        String sql="delete from admin where name='king'";
        PreparedStatement statement = connection.prepareStatement(sql);
//        statement.setString(1,admin_name);
//        statement.setString(2,admin_pwd);

//        ResultSet resultSet = statement.executeQuery();
//       if(resultSet.next()){
//           System.out.println("恭喜你登陆成功");
//       }else {
//           System.out.println("登录失败");
//       }

        int rows = statement.executeUpdate();
        System.out.println(rows>0?"成功":"失败");
//        resultSet.close();
        statement.close();
        connection.close();
    }
}
